package com.anosine.gpsl.android.presenter;

import com.anosine.gpsl.android.dao.ValidateDao;
import com.anosine.gpsl.android.entity.Login;
import com.anosine.gpsl.android.impl.ValidateDaoImpl;
import com.anosine.gpsl.android.presenter.BasePresenterActivity.OnLoadListener;
import com.anosine.gpsl.android.ui.ValidateView;
import com.lidroid.xutils.util.LogUtils;

/**
 * @Title: ValidatePresenter
 * @Package com.anosine.gpsl.android.presenter
 * @Description: 接收impl传递过来的JSON语句后的数据，并且改为实体后放入View的方法中传递给View
 * @author: sunny
 * @date: 2015-11-19
 * @version V1.0
 */
public class ValidatePresenter extends BasePresenterActivity implements OnLoadListener {
	private ValidateDao dao;
	private ValidateView view;

	/**
	 * @Title: ValidatePresenter(ValidateView view)
	 * @Description: 构造方法，初始化
	 * @param: view
	 * @throws
	 */
	public ValidatePresenter(ValidateView view) {
		super();
		this.dao = new ValidateDaoImpl(this);
		this.view = view;
	}

	/**
	 * @Title:loadValidate(String username,String imeino, String realname,String
	 *                            ChannelId,String idno, String imsino,String
	 *                            mobilebrank,String isAndroid,String
	 *                            baidupushid ,String mobilemodel)
	 * @Description: 调用登录验证接口，参数赋值
	 * @param: username 用户名
	 * @param: imeino IMEI号
	 * @param: realname 真实姓名
	 * @param: ChannelId 百度推送channelId
	 * @param: idno 身份证后8位
	 * @param: imsino IMSI号
	 * @param: mobilebrank 手机品牌
	 * @param: isAndroid 手机系统，1为android
	 * @param: baidupushid 百度推送ID
	 * @param: mobilemodel 手机型号
	 * @return: 无
	 * @throws
	 */

	public void loadValidate(String username, String imeino, String realname,
			String ChannelId, String idno, String imsino, String mobilebrank,
			String isAndroid, String baidupushid, String mobilemodel) {
		dao.getValidate(username, imeino, realname, ChannelId, idno, imsino,
				mobilebrank, isAndroid, baidupushid, mobilemodel);
	}

	/**
	 * @Title: onLoadStart()
	 * @Description: 重写加载开始方法
	 * @param: 无
	 * @return: 无
	 * @throws
	 */
	@Override
	public void onLoadStart() {
		LogUtils.d("获取登录验证信息加载中。。");
	}

	/**
	 * @Title: onFailure()
	 * @Description: 重写加载失败方法
	 * @param: 无
	 * @return: 无
	 * @throws
	 */
	@Override
	public void onFailure() {
		LogUtils.d("获取登录验证信息加载失败。。");
	}

	/**
	 * @Title: onSuccess(Object obj)
	 * @Description: 重写加载成功方法
	 * @param: Object obj
	 * @return: 无
	 * @throws
	 */
	@Override
	public void onSuccess(Object obj) {
		Login res = (Login) obj;
		checkLoginSuccess(res);
	}

	/**
	 * @Title: checkLoginSuccess(Login res)
	 * @Description: 将传递过来的JSON语句解析后的数据改为实体后放入ValidateView的方法中传递给View
	 * @param: Login res
	 * @return: 无
	 * @throws
	 */
	private void checkLoginSuccess(Login res) {
		this.view.setValidate(res);
	}
}
